package com.example.canteen.service.impl;

import com.example.canteen.dao.AdminDao;
import com.example.canteen.dao.impl.AdminDaoImpl;
import com.example.canteen.domain.Admin;
import com.example.canteen.service.AdminService;

import java.util.List;

public class AdminServiceImpl implements AdminService {
    private AdminDao adminDao = new AdminDaoImpl();
    @Override
    public boolean register(Admin admin) {
        Admin a = adminDao.findById(admin.getId());
        if(a!=null) {
            return false;
        }
        adminDao.save(admin);
        return true;
    }

    @Override
    public Admin login(int id, String password) {
        return adminDao.findByUsernameAndPassword(id, password);
    }

    @Override
    public boolean update(Admin admin) {
        if(adminDao.update(admin)==0){
            return false;
        }
        return true;
    }

    @Override
    public List<Admin> findAll() {
        return adminDao.findAll();
    }

    @Override
    public boolean delete(int id) {
        if (adminDao.delete(id)==0){
            return false;
        }
        return true;
    }

    @Override
    public boolean valid_id(int id) {
        Admin a = adminDao.findById(id);
        if(a==null){
            return true;
        }
        return false;
    }

    @Override
    public Admin findById(int id) {
        Admin a = adminDao.findById(id);
        return a;
    }
}
